Declare @MainCallStatusTypeID int
Declare @StatusCode int
Declare @MainEN nvarchar(255)
Declare @SubEN nvarchar(255)
Declare @strHTML nvarchar(Max)
SET @strHTML = '<html><body><table><tr><th>MainID</th><th>MainEN</th><th>SubID</th><th>SubEN</th></tr>'

Declare curMainStatus cursor for
	Select MainCallStatusTypeID, EN from tblCXCRMMainCallStatusType Where Status = 1 ORDER BY MainCallStatusTypeID
	
	Open curMainStatus 
		fetch next from curMainStatus into @MainCallStatusTypeID, @MainEN
		
		WHILE (@@fetch_status <> -1)
		BEGIN
			Declare curSubStatus cursor for
			Select StatusCode, EN from tblCXCRMCallStatusType Where MainCallStatusTypeID = @MainCallStatusTypeID And Status = 1
			
			Open curSubStatus 
			fetch next from curSubStatus into @StatusCode, @SubEN
				
				WHILE (@@fetch_status <> -1)
				BEGIN
						--Select @MainCallStatusTypeID, @MainEN, @StatusCode, @SubEN
						SET @strHTML = @strHTML + '<tr>'
						SET @strHTML = @strHTML + '<td>' + Cast(@MainCallStatusTypeID as varchar) + '</td>'
						SET @strHTML = @strHTML + '<td>' + Cast(@MainEN as varchar) + '</td>'
						SET @strHTML = @strHTML + '<td>' + Cast(@StatusCode as varchar) + '</td>'
						SET @strHTML = @strHTML + '<td>' + Cast(@SubEN as varchar) + '</td>'
						SET @strHTML = @strHTML + '</tr>'
						
				fetch next from curSubStatus into @StatusCode, @SubEN
				END
				
			Close curSubStatus
			Deallocate curSubStatus
		fetch next from curMainStatus into @MainCallStatusTypeID, @MainEN
		END
			
Close curMainStatus
Deallocate curMainStatus

SET @strHTML = @strHTML + '</table></body></html>'
PRINT @strHTML
select @strHTML